package threads;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.Socket;
import java.net.SocketAddress;

import domain.ClientDomainController;

public class ReceiveStopBroadcast extends Thread {

	private static final int STOP_BROADCAST_PORT = 8889;
	private ClientDomainController dc;
	private DatagramSocket datagramSocket;
	private byte[] buffer;
	private DatagramPacket inPacket;

	public ReceiveStopBroadcast(ClientDomainController dc) {
		super("receiveBroadcast");
		this.dc = dc;
	}

	@Override
	public void run() {
		super.run();
		while(true){
			try{
				datagramSocket = new DatagramSocket(STOP_BROADCAST_PORT);
				buffer = new byte[256];
				inPacket = new DatagramPacket(buffer, buffer.length);
				datagramSocket.receive(inPacket);
				dc.stopBroadcasting();
				System.out.println("Client received request to stop broadcast");
				datagramSocket.close();
			}catch (IOException e) {
				System.out.println("Client=>error on stop broadcasting "+ e);
			}
		}
	}
	
	
	
	

}
